# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     users.py
    Description:   
 -------------------------------------------------
 """
from fastapi import APIRouter, Depends, HTTPException
from app.api.v1.schemas.user import User, UserCreate
from app.api.v1.services.user_service import register_user

router = APIRouter()


@router.post("/", response_model=User)
def create_new_user(user: UserCreate, db: Depends(get_db)):
    return register_user(user, db)


@router.get("/{username}", response_model=User)
def get_user_by_username(username: str, db: Depends(get_db)):
    db_user = get_user_by_username(db, username)
    if db_user is None:
        raise HTTPException(status_code=404, detail="User not found")
    return db_user
